using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Resource.@string;
using MicroMsg.Scene;
using MicroMsg.Storage;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Windows.Media.Imaging;
namespace MicroMsg.Manager
{
	public class ConversationMgr
	{
		public const string TAG = "ConversationMgr";
		public const string DEFAULT_BACKGROUND_USER_NAME = "DEFAULT_BACKGROUND_USER_NAME";
		public const int ChatTxtStatus = 1;
		public const int ChatVoiceStatus = 0;
		private EventWatcher chatMsgAddWatcher;
		private EventWatcher chatMsgModifyWatcher;
		private EventWatcher chatMsgDelWatcher;
		private EventWatcher conversationModifyWatcher;
		private EventWatcher syncStatusWatcher;
		private int addMsgCount;
		private string newMsgSender;
		public ConversationMgr()
		{
			this.chatMsgAddWatcher = new EventWatcher(this, null, new EventHandlerDelegate(this.onChatAddMsgChange));
			this.chatMsgModifyWatcher = new EventWatcher(this, null, new EventHandlerDelegate(this.onChatModifyMsgChange));
			this.chatMsgDelWatcher = new EventWatcher(this, null, new EventHandlerDelegate(this.onChatMsgDelChange));
			this.conversationModifyWatcher = new EventWatcher(this, null, new EventHandlerDelegate(this.onConversationChange));
			this.syncStatusWatcher = new EventWatcher(this, null, new EventHandlerDelegate(this.onSyncStatusChange));
			EventCenter.registerEventWatcher(EventConst.ON_STORAGE_CONVERSATION_ADD, this.conversationModifyWatcher);
			EventCenter.registerEventWatcher(EventConst.ON_STORAGE_CONVERSATION_MODIFY, this.conversationModifyWatcher);
			EventCenter.registerEventWatcher(EventConst.ON_STORAGE_CHAT_MSG_ADD, this.chatMsgAddWatcher);
			EventCenter.registerEventWatcher(EventConst.ON_STORAGE_CHAT_MSG_MODIFY, this.chatMsgModifyWatcher);
			EventCenter.registerEventWatcher(EventConst.ON_STORAGE_CHAT_MSG_DEL, this.chatMsgDelWatcher);
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_SYNC, this.syncStatusWatcher);
			EventCenter.registerEventHandler(EventConst.ON_CONVERSATION_POST_SYCN_DATA, new EventHandlerDelegate(ConversationMgr.onPostSyncData));
		}
		public void Unit()
		{
			EventCenter.removeEventWatcher(EventConst.ON_STORAGE_CONVERSATION_ADD, this.conversationModifyWatcher);
			EventCenter.removeEventWatcher(EventConst.ON_STORAGE_CONVERSATION_MODIFY, this.conversationModifyWatcher);
			EventCenter.removeEventWatcher(EventConst.ON_STORAGE_CHAT_MSG_ADD, this.chatMsgAddWatcher);
			EventCenter.removeEventWatcher(EventConst.ON_STORAGE_CHAT_MSG_MODIFY, this.chatMsgModifyWatcher);
			EventCenter.removeEventWatcher(EventConst.ON_STORAGE_CHAT_MSG_DEL, this.chatMsgDelWatcher);
			EventCenter.removeEventHandler(EventConst.ON_CONVERSATION_POST_SYCN_DATA, new EventHandlerDelegate(ConversationMgr.onPostSyncData));
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_SYNC, this.syncStatusWatcher);
		}
		public ObservableCollection<Conversation> getList()
		{
			List<Conversation> list = StorageMgr.converation.getList();
			if (list == null)
			{
				return null;
			}
			return new ObservableCollection<Conversation>(list);
		}
		private static void onPostSyncData(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs != null && evtArgs.mObject != null)
			{
				StorageMgr.converation.setFlushCompleteHandler(evtArgs.mObject as Action);
				return;
			}
			Log.smethod_5("ConversationMgr", "onPostSyncData  args  error !");
		}
		public static void SetSaveCompleteHandler(Action onComplete)
		{
			if (onComplete == null)
			{
				return;
			}
			EventCenter.postEvent(EventConst.ON_CONVERSATION_POST_SYCN_DATA, onComplete, null);
		}
		private void ChatAddMsg(AddMsgInfo addInfo)
		{
			if (addInfo == null)
			{
				return;
			}
			if (addInfo.chatMsg_0 == null)
			{
				return;
			}
			if (!addInfo.chatMsg_0.IsSupport())
			{
				return;
			}
			if (addInfo.chatMsg_0.nIsSender != 1)
			{
				this.addMsgCount += addInfo.msgCount;
				this.newMsgSender = addInfo.chatMsg_0.strTalker;
			}
			this.ChatUpdateMsg(addInfo.chatMsg_0, true, addInfo.msgCount);
		}
		public static void GetChatStatus(string username, ref int chatStatus, ref string string_0)
		{
			chatStatus = 0;
			string_0 = "";
			if (string.IsNullOrEmpty(username))
			{
				return;
			}
			Contact contact = StorageMgr.contact.method_0(username);
			if (contact == null)
			{
				return;
			}
			chatStatus = contact.nInputType;
			if (contact.strInputText != null)
			{
				string_0 = contact.strInputText;
			}
		}
		public static void SaveChatStatus(string username, int chatStatus, string string_0)
		{
			if (string.IsNullOrEmpty(username) || string_0 == null)
			{
				return;
			}
			Contact contact = StorageMgr.contact.method_0(username);
			if (contact == null)
			{
				return;
			}
			contact.nInputType = chatStatus;
			contact.strInputText = string_0;
			StorageMgr.contact.modify(contact);
		}
		private void onSyncStatusChange(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs == null)
			{
				return;
			}
			NetSceneSyncResult netSceneSyncResult = evtArgs.mObject as NetSceneSyncResult;
			if (netSceneSyncResult == null)
			{
				Log.smethod_1("ConversationMgr", "NetSceneSyncResult == null");
				return;
			}
			if (netSceneSyncResult.syncStatus == SyncStatus.syncBegin)
			{
				this.addMsgCount = 0;
				return;
			}
			if (netSceneSyncResult.syncStatus == SyncStatus.syncEnd)
			{
				if (this.addMsgCount > 0 && netSceneSyncResult.hasNewMsg)
				{
					MsgNotifyMgr.DoNotify(this.newMsgSender);
				}
				this.addMsgCount = 0;
				return;
			}
			Log.smethod_1("ConversationMgr", "result.syncStatus == " + netSceneSyncResult.syncStatus);
		}
		public static void UpdateConversationFromMsg(ChatMsg chatMsg_0, Conversation conv, bool isNewMsg)
		{
			if (chatMsg_0 != null && conv != null)
			{
				conv.nMsgLocalID = chatMsg_0.nMsgLocalID;
				conv.strUsrName = chatMsg_0.strTalker;
				conv.nIsSend = chatMsg_0.nIsSender;
				if (isNewMsg)
				{
					conv.nTime = chatMsg_0.nCreateTime;
				}
				else
				{
					if (conv.nTime <= 0L)
					{
						conv.nTime = chatMsg_0.nCreateTime;
					}
				}
				if (chatMsg_0.IsVoice())
				{
					if (!chatMsg_0.IsSender() && ChatMsgMgr.getVoiceStatus(chatMsg_0) == MsgReadStatus.MsgUnRead)
					{
						conv.nStatus = 0;
					}
					else
					{
						conv.nStatus = 1;
					}
				}
				conv.strMsgType = string.Concat(chatMsg_0.nMsgType);
				if (ContactMgr.getUserType(conv.strUsrName) == ContactMgr.UserType.UserTypeChatRoom)
				{
					int num = 0;
					conv.strNickName = ContactHelper.getChatRoomStringInSession(conv.strUsrName, ref num);
				}
				else
				{
					conv.strNickName = ContactHelper.getDisplayName(conv.strUsrName, null);
				}
				conv.strContent = chatMsg_0.strMsg;
				if (conv.strContent != null && conv.strContent.get_Length() >= 3000)
				{
					conv.strContent = conv.strContent.Substring(0, 3000);
				}
				if (ContactHelper.isBlogAppContact(chatMsg_0.strTalker))
				{
					List<TXNews> list = BlogConversationMgr.convertChatMsg2BlogMsgList(chatMsg_0);
					if (list != null && list.get_Count() > 0)
					{
						conv.strContent = list.get_Item(0).strTitle;
					}
					else
					{
						conv.strContent = "";
					}
				}
				if (ContactHelper.isNewsContact(chatMsg_0.strTalker))
				{
					TXNews tXNews = NewsMgr.parseNewsXml(chatMsg_0.strMsg);
					if (tXNews != null)
					{
						conv.strContent = tXNews.strTitle;
						NewsMgr.getNewsImg(tXNews.strCoverImgUrl);
					}
				}
				if (ContactHelper.isQQMailContact(chatMsg_0.strTalker))
				{
					QQMail qQMail = QQMailMgr.parseMailXml(chatMsg_0.strMsg);
					if (qQMail != null)
					{
						conv.strContent = qQMail.strSender + ": " + qQMail.strTitle;
					}
				}
				if (chatMsg_0.nMsgType == 42)
				{
					string xmlStr = "";
					string senderusername = "";
					if (ContactHelper.isChatRoom(chatMsg_0.strTalker) && chatMsg_0.nIsSender != 1)
					{
						ChatMsgMgr.getMsgUser(chatMsg_0, ref senderusername, ref xmlStr);
					}
					else
					{
						xmlStr = chatMsg_0.strMsg;
						senderusername = chatMsg_0.strTalker;
					}
					CardMsgInfo cardMsgInfo = CardParse.ParseCardMsgInfoXML(xmlStr);
					if (cardMsgInfo == null)
					{
						conv.strContent = "";
					}
					else
					{
						conv.strContent = cardMsgInfo.ConversationInfo(chatMsg_0, senderusername);
					}
				}
				if (chatMsg_0.nMsgType == 37)
				{
					string xmlStr2 = "";
					string text = "";
					if (ContactHelper.isChatRoom(chatMsg_0.strTalker) && chatMsg_0.nIsSender != 1)
					{
						ChatMsgMgr.getMsgUser(chatMsg_0, ref text, ref xmlStr2);
					}
					else
					{
						xmlStr2 = chatMsg_0.strMsg;
						text = chatMsg_0.strTalker;
					}
					IFmessageInfo fmessageInfo = FMessageHelper.ParseValidFMessageXML(xmlStr2);
					if (fmessageInfo == null)
					{
						conv.strContent = "";
					}
					else
					{
						conv.strContent = fmessageInfo.ConversationInfo;
					}
				}
				if (chatMsg_0.IsAppMsg())
				{
					AppMsgInfo appMsgInfo = AppMsgMgr.parseAppXml(chatMsg_0.strMsg);
					conv.strContent = "";
					if (appMsgInfo != null && appMsgInfo.showtype == 1)
					{
						conv.strContent = appMsgInfo.title;
					}
					else
					{
						if (ContactHelper.isChatRoom(chatMsg_0.strTalker) && chatMsg_0.nIsSender != 1)
						{
							string text2 = "";
							string text3 = "";
							if (ChatMsgMgr.getMsgUser(chatMsg_0, ref text3, ref text2) && !string.IsNullOrEmpty(text3) && text3 != chatMsg_0.strTalker)
							{
								string displayName = ContactHelper.getDisplayName(text3, null);
								conv.strContent = displayName + ": ";
							}
						}
					}
					if (appMsgInfo != null && appMsgInfo.type == 1)
					{
						conv.strContent += appMsgInfo.title;
						return;
					}
					if (appMsgInfo != null && appMsgInfo.type == 2)
					{
						conv.strContent += strings.ChatImgContent;
						return;
					}
					if (appMsgInfo != null && appMsgInfo.type == 3)
					{
						conv.strContent += strings.ChatMusicContent;
						return;
					}
					if (appMsgInfo != null && appMsgInfo.type == 4)
					{
						conv.strContent += strings.ChatVideoContent;
						return;
					}
					if (appMsgInfo != null && appMsgInfo.type == 5)
					{
						conv.strContent += strings.ChatURLContent;
						return;
					}
					if (appMsgInfo != null && appMsgInfo.type == 6)
					{
						conv.strContent += strings.ChatFileContent;
						return;
					}
					if (appMsgInfo != null && appMsgInfo.type == 7)
					{
						conv.strContent += strings.ChatAppOpenContent;
						return;
					}
					if (appMsgInfo != null && appMsgInfo.type == 8)
					{
						conv.strContent += strings.MessageContent_Emoticon;
						return;
					}
					Log.smethod_1("ConversationMgr", "invalid appmsg, xml = " + chatMsg_0.strMsg);
				}
				return;
			}
		}
		private void SetMsgRead(Conversation item, ChatMsg chatMsg_0)
		{
			if (chatMsg_0 == null)
			{
				return;
			}
			if (item == null)
			{
				return;
			}
			item.nStatus = 1;
			if (chatMsg_0.IsVoice() && chatMsg_0.nIsSender == 0 && !ChatMsgMgr.getVoiceMsgIsRead(chatMsg_0))
			{
				item.nStatus = 0;
			}
		}
		public void SetMsgUnRead(Conversation item, ChatMsg chatMsg_0)
		{
			if (chatMsg_0 == null)
			{
				return;
			}
			if (item == null)
			{
				return;
			}
			if (chatMsg_0.IsSysInfo())
			{
				item.nStatus = 1;
				return;
			}
			item.nStatus = 0;
		}
		private void ChatUpdateMsg(ChatMsg chatMsg_0, bool isAddMsg = false, int combinMsgCount = 1)
		{
			if (chatMsg_0 == null)
			{
				return;
			}
			if (!chatMsg_0.IsSupport())
			{
				return;
			}
			if (chatMsg_0.IsPushMsg())
			{
				BannerManager.OnGetBannerMsg(chatMsg_0);
				return;
			}
			if (!chatMsg_0.IsSupportConversation())
			{
				return;
			}
			Conversation conversation = StorageMgr.converation.method_0(chatMsg_0.strTalker);
			if (conversation == null)
			{
				conversation = new Conversation();
				ConversationMgr.UpdateConversationFromMsg(chatMsg_0, conversation, isAddMsg);
				conversation.nStatus = 1;
				if (conversation.nIsSend == 1)
				{
					conversation.nUnReadCount = 0;
				}
				else
				{
					if (PageManager.IsTalkingToUser(conversation.strUsrName))
					{
						conversation.nUnReadCount = 0;
						this.SetMsgRead(conversation, chatMsg_0);
					}
					else
					{
						conversation.nUnReadCount = combinMsgCount;
						this.SetMsgUnRead(conversation, chatMsg_0);
					}
				}
				Log.smethod_5("ConversationMgr", "StorageMgr.converation.add start");
				StorageMgr.converation.vmethod_0(conversation);
				Log.smethod_5("ConversationMgr", "StorageMgr.converation.add end");
				return;
			}
			if (!isAddMsg && conversation.nMsgLocalID != chatMsg_0.nMsgLocalID)
			{
				return;
			}
			ConversationMgr.UpdateConversationFromMsg(chatMsg_0, conversation, isAddMsg);
			this.SetMsgRead(conversation, chatMsg_0);
			if (isAddMsg && chatMsg_0.nIsSender != 1)
			{
				if (PageManager.IsTalkingToUser(conversation.strUsrName))
				{
					conversation.nUnReadCount = 0;
					this.SetMsgRead(conversation, chatMsg_0);
				}
				else
				{
					conversation.nUnReadCount += combinMsgCount;
					this.SetMsgUnRead(conversation, chatMsg_0);
				}
			}
			Log.smethod_5("ConversationMgr", "StorageMgr.converation.update start");
			StorageMgr.converation.update(conversation);
			Log.smethod_5("ConversationMgr", "StorageMgr.converation.update end");
		}
		private List<AddMsgInfo> CombinationMsg(List<ChatMsg> listArgs)
		{
			if (listArgs != null && listArgs.get_Count() != 0)
			{
				Log.smethod_5("ConversationMgr", "CombinationMsg,List count:" + listArgs.get_Count());
				List<AddMsgInfo> list = new List<AddMsgInfo>();
				Dictionary<string, int> dictionary = new Dictionary<string, int>();
				for (int i = 0; i < listArgs.get_Count(); i++)
				{
					ChatMsg chatMsg = listArgs.get_Item(i);
					if (chatMsg != null && !string.IsNullOrEmpty(chatMsg.strTalker))
					{
						if (dictionary.ContainsKey(chatMsg.strTalker))
						{
							int num = dictionary.get_Item(chatMsg.strTalker);
							ChatMsg arg_8D_0 = list.get_Item(num).chatMsg_0;
							if (chatMsg.nMsgLocalID > list.get_Item(num).chatMsg_0.nMsgLocalID)
							{
								list.get_Item(num).chatMsg_0 = chatMsg;
							}
							if (chatMsg.nIsSender == 1)
							{
								list.get_Item(num).msgCount = 0;
							}
							else
							{
								if (!chatMsg.IsSysInfo())
								{
									list.get_Item(num).msgCount++;
								}
								if (!chatMsg.IsSysInfo() && !PageManager.IsTalkingToUser(chatMsg.strTalker))
								{
									list.get_Item(num).msgCountWithoutTalker++;
								}
							}
						}
						else
						{
							dictionary.set_Item(chatMsg.strTalker, list.get_Count());
							AddMsgInfo addMsgInfo = new AddMsgInfo();
							addMsgInfo.chatMsg_0 = chatMsg;
							if (chatMsg.nIsSender == 1)
							{
								addMsgInfo.msgCount = 0;
							}
							else
							{
								if (!chatMsg.IsSysInfo())
								{
									if (!PageManager.IsTalkingToUser(chatMsg.strTalker))
									{
										addMsgInfo.msgCountWithoutTalker = 1;
									}
									addMsgInfo.msgCount = 1;
								}
								else
								{
									addMsgInfo.msgCount = 0;
								}
							}
							list.Add(addMsgInfo);
						}
					}
				}
				Log.smethod_5("ConversationMgr", "CombinationMsg,after combin List count:" + list.get_Count());
				return list;
			}
			return null;
		}
		private void onChatAddMsgChange(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			List<ChatMsg> listObject = evtArgs.getListObject<ChatMsg>();
			if (listObject == null)
			{
				return;
			}
			using (List<ChatMsg>.Enumerator enumerator = listObject.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					ChatMsg current = enumerator.get_Current();
					FMsgMgr.addFMsg(current);
				}
			}
			List<AddMsgInfo> list = this.CombinationMsg(listObject);
			if (list != null && list.get_Count() != 0)
			{
				Log.smethod_5("ConversationMgr", "onChatAddMsgChange start");
				using (List<AddMsgInfo>.Enumerator enumerator2 = list.GetEnumerator())
				{
					while (enumerator2.MoveNext())
					{
						AddMsgInfo current2 = enumerator2.get_Current();
						this.ChatAddMsg(current2);
					}
				}
				Log.smethod_5("ConversationMgr", "onChatAddMsgChange end");
				return;
			}
		}
		private void onConversationChange(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs.getListObject<Conversation>() == null)
			{
				return;
			}
			EventCenter.postEvent(EventConst.ON_CONVERSATION_LIST_CHNAGE, evtArgs.mObject, null);
		}
		private void onChatModifyMsgChange(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			Log.smethod_5("ConversationMgr", "onChatModifyMsgChange start");
			List<ChatMsg> listObject = evtArgs.getListObject<ChatMsg>();
			if (listObject == null)
			{
				return;
			}
			using (List<ChatMsg>.Enumerator enumerator = listObject.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					ChatMsg current = enumerator.get_Current();
					FMsgMgr.addFMsg(current);
				}
			}
			using (List<ChatMsg>.Enumerator enumerator2 = listObject.GetEnumerator())
			{
				while (enumerator2.MoveNext())
				{
					ChatMsg current2 = enumerator2.get_Current();
					this.ChatUpdateMsg(current2, false, 1);
				}
			}
			Log.smethod_5("ConversationMgr", "onChatModifyMsgChange end");
		}
		private void onChatMsgDelChange(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs == null)
			{
				return;
			}
			List<ChatMsg> listObject = evtArgs.getListObject<ChatMsg>();
			if (listObject == null)
			{
				return;
			}
			using (List<ChatMsg>.Enumerator enumerator = listObject.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					ChatMsg current = enumerator.get_Current();
					Conversation conversation = StorageMgr.converation.method_0(current.strTalker);
					if (conversation != null && conversation.nMsgLocalID == current.nMsgLocalID)
					{
						int msgNum = StorageMgr.chatMsg.getMsgNum(conversation.strUsrName);
						if (msgNum <= 0)
						{
							conversation.strContent = "";
							conversation.strMsgType = string.Concat(1);
							conversation.nMsgLocalID = -1;
							StorageMgr.converation.modify(conversation);
						}
						else
						{
							List<ChatMsg> msgList = StorageMgr.chatMsg.getMsgList(conversation.strUsrName, msgNum - 1, 1);
							if (msgList != null && msgList.get_Count() > 0)
							{
								ConversationMgr.UpdateConversationFromMsg(msgList.get_Item(0), conversation, false);
								StorageMgr.converation.modify(conversation);
							}
						}
					}
				}
			}
		}
		public static void clearAll()
		{
			StorageMgr.converation.clearAll();
			StorageIO.emptyDir(StorageIO.getConversationBgPath());
		}
		public static int GetMsgType(string msgType)
		{
			int result = 1;
			if (string.IsNullOrEmpty(msgType))
			{
				return result;
			}
			try
			{
				result = int.Parse(msgType);
			}
			catch (Exception)
			{
				result = 1;
			}
			return result;
		}
		public static bool IsFmessage(Conversation conversation_0)
		{
			return conversation_0 != null && !string.IsNullOrEmpty(conversation_0.strUsrName) && conversation_0.strUsrName == "fmessage";
		}
		public static bool IsQmessage(Conversation conversation_0)
		{
			return conversation_0 != null && !string.IsNullOrEmpty(conversation_0.strUsrName) && conversation_0.strUsrName == "qmessage";
		}
		public static bool IsBmessage(Conversation conversation_0)
		{
			return conversation_0 != null && !string.IsNullOrEmpty(conversation_0.strUsrName) && conversation_0.strUsrName == "floatbottle";
		}
		public static bool IsMassMsg(Conversation conversation_0)
		{
			return conversation_0 != null && !string.IsNullOrEmpty(conversation_0.strUsrName) && conversation_0.strUsrName == "masssend";
		}
		public static bool delConversationAndRemoveFromContact(string talker)
		{
			if (!ConversationMgr.delConversation(talker))
			{
				return false;
			}
			Contact contact_ = StorageMgr.contact.method_0(talker);
			ContactMgr.operationSetContact(contact_, false);
			return true;
		}
		public static bool delConversation(string talker)
		{
			if (string.IsNullOrEmpty(talker))
			{
				return false;
			}
			if (ContactMgr.getUserType(talker) != ContactMgr.UserType.UserTypeNormal && ContactMgr.getUserType(talker) != ContactMgr.UserType.UserTypePlugin)
			{
				Log.smethod_1("ConversationMgr", "invalid talker" + talker);
				return false;
			}
			ChatMsgMgr.deleteMsgByTalker(talker);
			return StorageMgr.converation.method_5(talker);
		}
		public static bool delChatRoomConversation(string chatRoomName)
		{
			if (string.IsNullOrEmpty(chatRoomName))
			{
				return false;
			}
			if (ContactMgr.getUserType(chatRoomName) != ContactMgr.UserType.UserTypeChatRoom)
			{
				Log.smethod_1("ConversationMgr", "invalid chatRoomName" + chatRoomName);
				return false;
			}
			ChatMsgMgr.deleteMsgByTalker(chatRoomName);
			Contact contact = StorageMgr.contact.method_0(chatRoomName);
			if (contact != null)
			{
				ContactMgr.operationSetChatroomContact(contact, false);
			}
			return StorageMgr.converation.method_5(chatRoomName);
		}
		public static bool IsSupport(Conversation conversation_0)
		{
			if (conversation_0 == null)
			{
				return false;
			}
			ContactMgr.UserType userType = ContactMgr.getUserType(conversation_0.strUsrName);
			bool result = false;
			if (!(conversation_0.strUsrName == "sysnotice"))
			{
				if (userType != ContactMgr.UserType.UserTypeChatRoom)
				{
					if (userType != ContactMgr.UserType.UserTypeNormal)
					{
						if (userType == ContactMgr.UserType.UserTypePlugin && (conversation_0.strUsrName == "weixin" || conversation_0.strUsrName == "fmessage" || conversation_0.strUsrName == "qmessage" || conversation_0.strUsrName == "floatbottle" || conversation_0.strUsrName == "masssend" || conversation_0.strUsrName == ConstantValue.TAG_BLOGAPP || conversation_0.strUsrName == ConstantValue.TAG_NEWS || conversation_0.strUsrName == ConstantValue.TAG_QQMAIL))
						{
							result = true;
							return result;
						}
						return result;
					}
				}
				result = true;
			}
			return result;
		}
		public static int getUnReadCountAll()
		{
			List<Conversation> list = StorageMgr.converation.getList();
			if (list != null && list.get_Count() > 0)
			{
				int num = 0;
				using (List<Conversation>.Enumerator enumerator = list.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						Conversation current = enumerator.get_Current();
						num += current.nUnReadCount;
					}
				}
				return num;
			}
			return 0;
		}
		public static bool setUnreadCount(string userName, int nUnReadCount, bool forcetoReaded = false)
		{
			if (string.IsNullOrEmpty(userName))
			{
				return false;
			}
			Conversation conversation = StorageMgr.converation.method_0(userName);
			if (conversation == null)
			{
				return false;
			}
			if (forcetoReaded)
			{
				conversation.nStatus = 1;
			}
			conversation.nUnReadCount = nUnReadCount;
			return StorageMgr.converation.modify(conversation);
		}
		private static string getBgFilePath(string userName)
		{
			if (string.IsNullOrEmpty(userName))
			{
				return null;
			}
			return StorageIO.getConversationBgPath() + "/" + userName + ".jpg";
		}
		public static void setBackGround(string userName, Stream fileStream)
		{
			if (string.IsNullOrEmpty(userName) || fileStream == null)
			{
				return;
			}
			if (!Util.saveJpeg(fileStream, ConversationMgr.getBgFilePath(userName), 480, 800, 70))
			{
				return;
			}
			ConversationBgSetting conversationBgSetting = ConfigMgr.smethod_0<ConversationBgSetting>();
			conversationBgSetting.mapBgSetting.set_Item(userName, ConversationMgr.getBgFilePath(userName));
			ConfigMgr.save<ConversationBgSetting>(false);
			ServiceCenter.statReportMgr.addStatItem(enKVStatKey.MM_BACKGROUND_USED, "-1");
		}
		public static void setBackGroundRes(string userName, string strResource)
		{
			if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(strResource))
			{
				ConversationBgSetting conversationBgSetting = ConfigMgr.smethod_0<ConversationBgSetting>();
				conversationBgSetting.mapBgSetting.set_Item(userName, "@" + strResource);
				ConfigMgr.save<ConversationBgSetting>(false);
				return;
			}
		}
		public static void setBackGroundSvr(string userName, string strFilePath)
		{
			if (!string.IsNullOrEmpty(userName) && strFilePath != null)
			{
				ConversationBgSetting conversationBgSetting = ConfigMgr.smethod_0<ConversationBgSetting>();
				conversationBgSetting.mapBgSetting.set_Item(userName, "#" + strFilePath);
				ConfigMgr.save<ConversationBgSetting>(false);
				return;
			}
		}
		public static BitmapImage getBackGround(string userName)
		{
			if (string.IsNullOrEmpty(userName))
			{
				return null;
			}
			ConversationBgSetting conversationBgSetting = ConfigMgr.smethod_0<ConversationBgSetting>();
			if (conversationBgSetting == null || conversationBgSetting.mapBgSetting == null)
			{
				return null;
			}
			if (!conversationBgSetting.mapBgSetting.ContainsKey(userName))
			{
				return null;
			}
			string text = conversationBgSetting.mapBgSetting.get_Item(userName);
			if (string.IsNullOrEmpty(text))
			{
				return null;
			}
			if (text.get_Chars(0) == '@')
			{
				return ImageCacheMgr.loadFromRes(text.Substring(1));
			}
			if (text.get_Chars(0) == '#')
			{
				return ImageCacheMgr.loadFromFile(text.Substring(1));
			}
			return ImageCacheMgr.loadFromFile(text);
		}
		public static void clearBackGround(string userName, bool bSave = true)
		{
			if (string.IsNullOrEmpty(userName))
			{
				return;
			}
			ConversationBgSetting conversationBgSetting = ConfigMgr.smethod_0<ConversationBgSetting>();
			if (conversationBgSetting != null && conversationBgSetting.mapBgSetting != null)
			{
				if (conversationBgSetting.mapBgSetting.ContainsKey(userName))
				{
					string text = conversationBgSetting.mapBgSetting.get_Item(userName);
					if (text != null && text.get_Chars(0) != '@' && text.get_Chars(0) != '#')
					{
						StorageIO.deleteFile(text);
					}
					conversationBgSetting.mapBgSetting.Remove(userName);
					if (bSave)
					{
						ConfigMgr.save<ConversationBgSetting>(false);
					}
				}
				return;
			}
		}
		public static void clearAllBackGround(bool bSave = true)
		{
			ConversationBgSetting conversationBgSetting = ConfigMgr.smethod_0<ConversationBgSetting>();
			using (Dictionary<string, string>.Enumerator enumerator = conversationBgSetting.mapBgSetting.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					KeyValuePair<string, string> current = enumerator.get_Current();
					if (!(current.get_Key() == "DEFAULT_BACKGROUND_USER_NAME") && current.get_Value().get_Chars(0) != '@' && current.get_Value().get_Chars(0) != '#')
					{
						StorageIO.deleteFile(current.get_Value());
					}
				}
			}
			string text = null;
			if (conversationBgSetting.mapBgSetting.ContainsKey("DEFAULT_BACKGROUND_USER_NAME"))
			{
				text = conversationBgSetting.mapBgSetting.get_Item("DEFAULT_BACKGROUND_USER_NAME");
			}
			conversationBgSetting.mapBgSetting.Clear();
			if (text != null)
			{
				conversationBgSetting.mapBgSetting.Add("DEFAULT_BACKGROUND_USER_NAME", text);
			}
			if (bSave)
			{
				ConfigMgr.save<ConversationBgSetting>(false);
			}
		}
		public static string getBackGroundPath(string userName)
		{
			if (string.IsNullOrEmpty(userName))
			{
				return null;
			}
			ConversationBgSetting conversationBgSetting = ConfigMgr.smethod_0<ConversationBgSetting>();
			if (conversationBgSetting == null || conversationBgSetting.mapBgSetting == null)
			{
				return null;
			}
			if (!conversationBgSetting.mapBgSetting.ContainsKey(userName))
			{
				return null;
			}
			string text = conversationBgSetting.mapBgSetting.get_Item(userName);
			if (text != null && text.get_Length() != 0)
			{
				if (text.get_Chars(0) != '@')
				{
					if (text.get_Chars(0) != '#')
					{
						return text;
					}
				}
				return text.Substring(1);
			}
			return null;
		}
	}
}
